package com.dhcc.utils.zip;

import java.io.InputStream;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class InputStreamIterator implements Iterator<NamedInputStream> {

	private Iterator<ZipEntry> it;
	private ZipFile zip;

	public InputStreamIterator(ZipFile file) {
		this.it = (Iterator<ZipEntry>) file.entries();
		this.zip = file;
	}
	
	@Override
	public boolean hasNext() {
		return it.hasNext();
	}

	@Override
	public NamedInputStream next() {
		ZipEntry next = it.next();
		try {
			return new NamedInputStream(next.getName(), zip.getInputStream(next));
		}catch(Exception ex) {
			throw new RuntimeException("获取流信息失败", ex);
		}
	}

}
